{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "mi,mx = 1,10000000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = random.randint(mi,mx)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2787030"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 5000000\n",
      "2 2500000\n",
      "3 3750000\n",
      "4 3125000\n",
      "5 2812500\n",
      "6 2656250\n",
      "7 2734375\n",
      "8 2773437\n",
      "9 2792968\n",
      "10 2783202\n",
      "11 2788085\n",
      "12 2785643\n",
      "13 2786864\n",
      "14 2787474\n",
      "15 2787169\n",
      "16 2787016\n",
      "17 2787092\n",
      "18 2787054\n",
      "19 2787035\n",
      "20 2787025\n",
      "21 2787030\n",
      "------------ 2787030\n"
     ]
    }
   ],
   "source": [
    "x,y = mi,mx\n",
    "i = 0\n",
    "while(True):\n",
    "    v = int((x+y)/2)\n",
    "    i+=1\n",
    "    print(i,v)\n",
    "    if v == r:\n",
    "        print(\"------------\",r)\n",
    "        break\n",
    "    if v < r :\n",
    "        x,y = v,y\n",
    "    else:\n",
    "        x,y = x,v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
